import { NestFactory } from '@nestjs/core';
import { Transport } from '@nestjs/microservices';
import { AppModule } from './app.module';
import { createClient, RedisClientType } from 'redis';

let C = createClient({ url: 'redis://localhost:6379' });
C.connect();
C.set('a', JSON.stringify({ a: 1, e: 2 })).then((res) => {
  C.get('a').then((p) => console.log(32453452345, JSON.parse(p).a));
});

async function bootstrap() {
  const redisClient = createClient({ url: 'redis://localhost:6379' });
  redisClient.connect();
  redisClient.subscribe('test', (message, channel) =>
    console.log(message, channel),
  );
  const app = await NestFactory.create(AppModule);
  const redis = await NestFactory.createMicroservice(AppModule, {
    transport: Transport.REDIS,
    options: {
      url: 'redis://localhost:6379',
    },
  });
  app.setGlobalPrefix('api');
  app.enableCors({
    origin: ['http://localhost:3322'],
    methods: '*',
  });
  await redis.listen().then((res) => console.log('redis listen!'));
  await app.listen(3006);
}
bootstrap();
